package com.todod.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.todod.entity.QueryEntry;
import com.todod.entity.ResultData;
import com.todod.model.Department;
import com.todod.model.OperateLog;
import com.todod.model.User;
import com.todod.service.IDepartmentService;
import com.todod.service.IUserService;
import com.todod.service.OperateLogService;

@RestController
@RequestMapping("/operateLog")
public class OperateLogController extends BaseManageController {

	@Autowired
	private OperateLogService operateLogService;
	@Autowired
	private IUserService iUserService;
	@Autowired
	private IDepartmentService departmentService;

	/**
	 * 分页查询
	 * 
	 * @Title: getPage
	 * @Description:
	 * @author gsh
	 * @date 2019年10月11日
	 * @param queryEntry
	 * @return
	 */
	@GetMapping("/getPage")
	public ResultData getPage(QueryEntry queryEntry) {
		IPage<OperateLog> page = operateLogService.getPage(queryEntry);

		return ResultData.success("ok", page);
	}

	/**
	 * 删除数据
	 */
	@PostMapping("/delete")
	public ResultData delete(@RequestAttribute Long _userId, String date) {

		User user = iUserService.getById(_userId);

		Department d = departmentService.getById(user.getDepartid());
		List<String> dIds = departmentService.getDownIdList(d, null); // 获取本级部门和子部门

		operateLogService.delete(user, date, dIds);

		return ResultData.success("ok");
	}

}
